package com.mbengue.corp.apr.ra.core;

import java.io.Serializable;

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;

@Entity
@Table(name = "articlemembre", schema = "apr_ra")
@NamedQueries(value = {
    @NamedQuery(name = "findByAuteur", query = "SELECT ad FROM ArticleMembre ad WHERE ad.membre=:auteur"),
    @NamedQuery(name = "findByArticle", query = "SELECT ad FROM ArticleMembre ad WHERE ad.article=:article"),
    @NamedQuery(name = "deleteByAuteur", query = "DELETE FROM ArticleMembre ad WHERE ad.membre=:auteur") })
public class ArticleMembre implements Serializable {
  private static final long serialVersionUID = 1L;
  private ArticleMembreId id;
  private Article article;
  private Membre membre;

  @EmbeddedId
  @AttributeOverrides({ @AttributeOverride(name = "idMembre", column = @Column(name = "idMembre", nullable = false)),
      @AttributeOverride(name = "idArticle", column = @Column(name = "idArticle", nullable = false)) })
  public ArticleMembreId getId() {
    return id;
  }

  public void setId(ArticleMembreId aId) {
    id = aId;
  }

  @OneToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "idArticle", nullable = false, insertable = false, updatable = false)
  public Article getArticle() {
    return article;
  }

  public void setArticle(Article aArticle) {
    article = aArticle;
  }

  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "idMembre", nullable = false, insertable = false, updatable = false)
  public Membre getMembre() {
    return membre;
  }

  public void setMembre(Membre aMembre) {
    membre = aMembre;
  }

  public ArticleMembre() {
    // TODO Auto-generated constructor stub
  }

  public ArticleMembre(ArticleMembreId aId, Article aArticle, Membre aMembre) {
    super();
    id = aId;
    article = aArticle;
    membre = aMembre;
  }
}
